//
//  RequestServices.m
//  HousingPoliceAssistant
//
//  Created by 云警01 on 2019/6/6.
//  Copyright © 2019 盛洋. All rights reserved.
//

#import "RequestServices.h"
#import "AFNetworking.h"
#import "MainService.h"

@interface RequestServices()
@property (nonatomic, strong) AFHTTPRequestOperationManager *manager;
@property (nonatomic, copy) NSString *specilUrl;

@end

@implementation RequestServices

#pragma mark - 初始化

- (id)initWithDelegate:(id)delegate
{
    if ((self = [super init])) {
        _manager = [AFHTTPRequestOperationManager manager];
        self.delegate = delegate;
    }
    
    return self;
}

-(void)cancel{
    _delegate = nil;
    [_manager.operationQueue cancelAllOperations];
    
}

#pragma mark ------------------------------------- 注册登录

#pragma mark --获取验证码
-(void)getMobileCode:(NSString *)mobile type:(NSString *)type tag:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                         mobile,@"mobile",
                         type,@"type",
                         nil];
    [self startHttpRequest:dic target:@"/app/user/captcha" tag:tag];
}

#pragma mark --登录
-(void)loginToApplication:(NSString *)mobile captcha:(NSString *)captcha messageDeviceToken:(NSString *)messageDeviceToken tag:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                         mobile,@"mobile",
                         captcha,@"captcha",
                         messageDeviceToken,@"messageDeviceToken",
                         nil];
    [self startHttpRequest:dic target:@"/app/user/login" tag:tag];
}

#pragma mark --注册完善信息
-(void)registerCount:(NSString *)userName gender:(NSString *)gender birthday:(NSString *)birthday tag:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                         userName,@"userName",
                         gender,@"gender",
                         birthday,@"birthday",
                         nil];
    [self startHttpRequest:dic target:@"/app/user/updateInfo" tag:tag];
}

#pragma mark --广告页 首页
-(void)getAdvert:(NSString *)type tag:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                         type,@"type",
                         nil];
    [self startHttpRequest:dic target:@"/app/advert" tag:tag];
}


#pragma mark -------------------------------------  个人中心

#pragma mark --版本检查
-(void)checkVersion:(NSString *)appType version:(NSString *)version tag:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                         appType,@"appType",
                         version,@"version",
                         nil];
    [self startHttpRequest:dic target:@"/app/upgrade" tag:tag];
}

#pragma mark --添加绑定设备
-(void)addLoginDevice:(NSString *)deviceId deviceName:(NSString *)deviceName tag:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                         deviceId,@"deviceId",
                         deviceName,@"deviceName",
                         nil];
    [self startHttpRequest:dic target:@"/app/settingdevicebind/addbinddevice" tag:tag];
}

#pragma mark --设备列表
-(void)getDeviceList:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionary];
    [self startHttpRequest:dic target:@"/app/settingdevicebind/listbinddevice" tag:tag];
}

#pragma mark --移除绑定设备
-(void)removeDevice:(NSString *)deviceId tag:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                          deviceId,@"deviceId",
                          nil];
     [self startHttpRequest:dic target:@"/app/settingdevicebind/removebinddevice" tag:tag];
}

#pragma mark --学习报告列表
-(void)studyRepoetList:(NSString *)page tag:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary
                         dictionaryWithObjectsAndKeys:
                         page,@"current",
                         @(20),@"size",
                         nil];
    [self startHttpRequest:dic target:@"/app/studyreport/list" tag:tag];
}

#pragma mark --获取用户信息
-(void)getUserInfor:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionary];
       [self startHttpRequest:dic target:@"/app/user/userInfo" tag:tag];
}


#pragma mark --设置-我的作品列表
-(void)myWorkList:(NSInteger)page type:(NSString *)type tag:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                         @(page),@"current",
                         @(20),@"size",
                         type,@"type",
                         nil];
    [self startHttpRequest:dic target:@"/app/production/myproduction" tag:tag];
}

#pragma mark --获取消息列表
-(void)getNewsList:(NSInteger)page type:(NSString *)type tag:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                            @(page),@"current",
                            @(20),@"size",
                            type,@"type",
                            nil];
       [self startHttpRequest:dic target:@"/app/message/getmessagelist" tag:tag];
}


#pragma mark --  获取邀请注册链接
-(void)getInviteHttp:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionary];
    [self startHttpRequest:dic target:@"/app/user/invitationToRegisterLink" tag:tag];
}


#pragma mark --  获取隐私设置协议标题列表
-(void)getProtocolList:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionary];
       [self startHttpRequest:dic target:@"/app/setting/agreementtitlelist" tag:tag];
}

#pragma mark -- 更新用户信息
-(void)updateUserInfor:(NSDictionary *)dic tag: (NSInteger)tag{
    NSDictionary *dic1 = [NSDictionary dictionaryWithDictionary:dic];
    [self startHttpRequest:dic1 target:@"/app/user/updateInfo" tag:tag];
}


#pragma mark ------------------------------------- 学习中心
#pragma mark -- 学科列表

-(void)getClassList:(NSString *)page tag:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                         page,@"page",
                         nil];
    [self startHttpRequest:dic target:@"/app/course/categoryList" tag:tag];
}

#pragma mark -- 学习中心-2 /推荐课程/课程目录
-(void)getCurriculumList:(NSString *)page categoryId:(NSString *)categoryId recommend:(NSString *)recommend stageId:(NSString *)stageId tag:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                         page,@"page",
                         categoryId,@"categoryId",
                         recommend,@"recommend",
                         stageId,@"stageId",
                         nil];
    [self startHttpRequest:dic target:@"/app/course/courseList" tag:tag];
}

#pragma mark -- 课程阶段列表
-(void)getStageList:(NSString *)categoryId tag:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                         categoryId,@"categoryId",
                         nil];
    [self startHttpRequest:dic target:@"/app/course/stageList" tag:tag];
}

#pragma mark -- 课程详情
-(void)getCourseInfor:(NSString *)courseId tag:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                         courseId,@"courseId",
                         nil];
    [self startHttpRequest:dic target:@"/app/course/courseDetail" tag:tag];
}

#pragma mark -- 课程参考资料
-(void)getClassData:(NSString *)courseId tag:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                         courseId,@"courseId",
                         nil];
    [self startHttpRequest:dic target:@"/app/course/referenceDetail" tag:tag];
}

#pragma mark -- 推荐作品
-(void)tuiJianZuoPin:(NSString *)page tag:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                         page,@"page",
                         nil];
    [self startHttpRequest:dic target:@"/app/course/productionRecommendList" tag:tag];
}

#pragma mark -- 上传作品
-(void)upLoadMyWorks:(NSString *)courseId desc:(NSString *)desc fileList:(NSArray *)fileList userId:(NSString *)userId tag:(NSInteger)tag{
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                         courseId,@"courseId",
                         desc,@"desc",
                         userId,@"userId",
                         nil];
    NSMutableArray *arr = [NSMutableArray array];
    if (fileList) {//后台要求数据格式要这样传。。。
        for (int i = 0; i<fileList.count; i++) {
            NSDictionary *dic = [NSDictionary dictionaryWithObject:fileList[i] forKey:@"proUrl"];
            [arr addObject:dic];
        }
        fileList = [NSArray arrayWithArray:arr];
    }
    [dic setObject:fileList forKey:@"fileList"];
    [self startHttpRequest:dic target:@"/app/course/submitProduction" tag:tag];
}

#pragma mark ------------------------------------- 试验中心
#pragma mark -- 获取试验中心列表
-(void)getTestCenterList:(NSString *)page type:(NSString *)type tag:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                         page,@"page",
                         type,@"type",
                         nil];
    [self startHttpRequest:dic target:@"/app/experiment/list" tag:tag];
}

#pragma mark -- 获取试验中心详情
-(void)getTestCenterInfor:(NSString *)id tag:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                         id,@"id",
                         nil];
    [self startHttpRequest:dic target:@"/app/experiment/detail" tag:tag];
}

#pragma mark -- 学习-测试-练习-上传作品-流程锁
-(void)getStepsLock:(NSString *)courseId tag:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                            courseId,@"courseId",
                            nil];
       [self startHttpRequest:dic target:@"/app/course/studyTestProductionLock" tag:tag];
}
#pragma mark -- 统计看视频时长
-(void)checkWatchVideo:(NSString *)course_id current_look_minutes:(NSString *)current_look_minutes max_video_minutes:(NSString *)max_video_minutes tag:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                         course_id,@"course_id",
                         current_look_minutes,@"current_look_minutes",
                         max_video_minutes,@"max_video_minutes",
                         nil];
    [self startHttpRequest:dic target:@"/app/studyreport/notevideo" tag:tag];
}

#pragma mark -- 练-测-题库
-(void)getQuestionBank:(NSString *)courseId current:(NSInteger)current size:(NSInteger)size type:(NSInteger)type tag:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                         courseId,@"courseId",
                         current,@"current",
                         size,@"size",
                         type,@"type",
                         nil];
    [self startHttpRequest:dic target:@"/app/course/courseLibrary" tag:tag];
}

#pragma mark ------------------------------------- 阿列夫赛道
#pragma mark --阿列夫赛道列表
-(void)requestAliefuGymList:(NSInteger)current size:(NSInteger)size status:(NSInteger)status type:(NSInteger)type keyword:(NSString *)keyword tag:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                         @(current),@"current",
                         @(size),@"size",
                         @(status),@"status",
                         @(type),@"type",
                         keyword,@"keyword",
                         nil];
    [self startHttpRequest:dic target:@"/app/match/search" tag:tag];
}

#pragma mark --活动/比赛详情
-(void)getGymInfor:(NSInteger)typeid tag:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                            @(typeid),@"typeid",
                            nil];
       [self startHttpRequest:dic target:@"/app/match/details" tag:tag];
}


#pragma mark --获取搜索热词
-(void)requestSearchWord:(NSInteger)type tag:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                            @(type),@"type",
                            nil];
       [self startHttpRequest:dic target:@"/app/getHotWord" tag:tag];
}

#pragma mark ---上传视频
-(void)requestUPLoadVideo:(NSString *)file tag:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionary];
    [self uploadVideoWithFilePath:@"/sys/oss/uploadMultipartFile" dic:dic video:file tag:tag];
}



#pragma mark -- 上传文件
-(void)upLoadFile:(NSArray *)file tag:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                         file,@"file",
                         nil];
    [self upLoadContenteToFile:dic target:@"/sys/oss/uploadMultipartFile" tag:tag];
}

#pragma mark -- 作品提交
-(void)requestUPLoad: (id)parmas tag:(NSInteger)tag{
    [self startHttpRequest:parmas target:@"/app/production/commit" tag:tag];
}

#pragma mark -- 优秀作品
-(void)getGoodProductionList:(NSInteger)typeid type:(NSInteger)type current:(NSInteger)current size:(NSInteger)size keyword:(NSString *)keyword tag:(NSInteger)tag{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                         @(typeid),@"typeid",
                         @(type),@"type",
                         @(current),@"current",
                         @(size),@"size",
                         keyword,@"keyword",
                         nil];
    [self startHttpRequest:dic target:@"/app/production/goodproductionlist" tag:tag];
}




#pragma mark ------------------------------ 上传视频
-(void)uploadVideoWithFilePath:(NSString *)url dic:(NSDictionary*)dic video:(NSString *)video tag:(NSInteger)tag{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    manager.requestSerializer.timeoutInterval = 15;
    [manager.requestSerializer setValue:NSUDGetToken forHTTPHeaderField:@"Authorization"];
    [manager.requestSerializer setValue:@"multipart/form-data" forHTTPHeaderField:@"Content-Type"];
     [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    
    [manager POST:[NSString stringWithFormat:@"%@%@?token=%@",GY_SERVER,url,NSUDGetToken] parameters:dic  constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        //上传视频的参数
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        formatter.dateFormat = @"yyyyMMddHHmmss";
        NSString *str = [formatter stringFromDate:[NSDate date]];
        NSString *fileName = [NSString stringWithFormat:@"%@.mp4", str];
        NSData *fileData = [NSData dataWithContentsOfFile:video];
        [formData appendPartWithFileData:fileData name:@"file" fileName:fileName mimeType:@"mp4"];
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//        NSLog(@"responseObject-->%@",responseObject);

        if ([responseObject[@"code"] intValue] == 200) {
            if(self->_delegate && [self->_delegate respondsToSelector:@selector(getFinished:tag:)]){
                [self->_delegate getFinished:responseObject[@"data"] tag:tag];
            }

        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        //网络问题
        [self ShowNewMsg:error.domain];
    }];
}

#pragma mark ------------------------------ 上传照片
-(void)upLoadContenteToFile:(NSDictionary*)dic target:(NSString*)target tag:(long long)tag{
    if (self.view) {
        [self ShowLoading];
    }
    NSArray *imagArr = dic[@"file"];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];//
    //接收类型不一致请替换一致text/html或别的//
    NSURLSessionDataTask *task = [manager POST:[NSString stringWithFormat:@"%@%@?token=%@",GY_SERVER,target,NSUDGetToken] parameters:nil
                     constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        if (imagArr && [imagArr[0] isKindOfClass:[UIImage class]]) {
            
            for (UIImage *image in imagArr) {
                
                NSData *imageData =UIImageJPEGRepresentation(image,0.8);
                
                NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
                
                formatter.dateFormat =@"yyyyMMddHHmmss";
                
                NSString *str = [formatter stringFromDate:[NSDate date]];
                
                NSString *fileName = [NSString stringWithFormat:@"%@.jpg", str];
                
                //上传的参数(上传图片，以文件流的格式)
                
                [formData appendPartWithFileData:imageData
                 
                                            name:@"file"
                 
                                        fileName:fileName
                 
                                        mimeType:@"image/jpeg"];
            }
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        [self HideLoading];
        //上传成功
        
        if(self->_delegate && [self->_delegate respondsToSelector:@selector(getFinished:tag:)]){
            [self->_delegate getFinished:responseObject[@"data"] tag:tag];
        } }failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            //请求失败
            [self HideLoading];
        }];
    
}


#pragma mark --------- 参数签名 & 网络请求
-(void)startHttpRequest:(NSDictionary*)dic target:(NSString*)target tag:(long long)tag{
    if (is_loading) {
        //当前正在进行请求,不要重复请求
        NSLog(@"当前正在进行请求,不要重复请求");
        return;
    }
    //判断是否有图片类型提交参数
    NSMutableDictionary *pDic = [[NSMutableDictionary alloc] initWithDictionary:dic];
    NSDictionary *dataDic = [NSDictionary dictionaryWithDictionary:pDic];

    
    if (self.view) {
        [self ShowLoading];
    }
    NSDictionary *body = dataDic;
    
    NSError *error;
  
    
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:body options:0 error:&error];
    
    NSString *json_String = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    
    AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
    NSMutableURLRequest *req = [[AFJSONRequestSerializer serializer] requestWithMethod:@"POST" URLString:[NSString stringWithFormat:@"%@%@?token=%@",GY_SERVER,target,NSUDGetToken] parameters:nil error:nil];
    
    req.timeoutInterval= [[[NSUserDefaults standardUserDefaults] valueForKey:@"timeoutInterval"] longValue];
    
    [req setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    
    [req setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [req setHTTPBody:[json_String dataUsingEncoding:NSUTF8StringEncoding]];
    
    NSLog(@"\r\n----------------服务器请求开始----------------\r\n请求地址:%@\r\n%@\r\n----------------服务器请求结束----------------",req,json_String);
    [[manager dataTaskWithRequest:req completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
        //请求成功
        if (!error) {
            [self HideLoading];
            NSLog(@"\r\n----------------服务器响应开始----------------\r\n获取到服务器返回的JSON:%@\r\n----------------服务器响应结束----------------", responseObject);
            //保存当前时间到本地
            [[DataService sharedService] SaveCurrentDayToLocal];
            
            //如果返回数据格式是字典
            if ([responseObject isKindOfClass:[NSDictionary class]]) {
                NSLog(@"返回的数据格式是字典");
            }
            
            NSString *msg;
            if ([[responseObject valueForKey:@"msg"] CheckNSStringData]) {
                msg = (NSString *)[responseObject valueForKey:@"msg"];
            }
            // 注:后台最好返回数据类型为string，避免后期解析出现不可预估的错误
            if ([responseObject[@"code"] intValue] == 2000) {
                //处理 登录过期
                [self ShowLoginOutDate:2];
                if(self->_delegate && [self->_delegate respondsToSelector:@selector(getError:tag:)]){
                    NSString *resMsg = @"";
                    if ([responseObject valueForKey:@"msg"]) {
                        resMsg = [responseObject valueForKey:@"msg"];
                    }
                    [self->_delegate getError:[NSError errorWithDomain:resMsg code:[[responseObject valueForKey:@"code"] integerValue] userInfo:nil] tag:tag];
                }
            }else if ([[responseObject valueForKey:@"code"] intValue] == 200) {//判断业务逻辑是否正常
                NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
                if ([responseObject valueForKey:@"data"] != nil && ![[responseObject valueForKey:@"data"] isKindOfClass:[NSDictionary class]]) {
                    [dic setObject:[responseObject valueForKey:@"data"] forKey:@"list"];
                }else {
                    dic = [[NSMutableDictionary alloc] initWithDictionary:[responseObject valueForKey:@"data"]];
                }
                
                [dic setValue:pDic forKey:@"postDic"];
                if(self->_delegate && [self->_delegate respondsToSelector:@selector(getFinished:tag:)]){
                    [self->_delegate getFinished:dic tag:tag];
                }
            }else{
                if(self->_delegate && [self->_delegate respondsToSelector:@selector(getError:tag:)]){
                    NSString *resMsg = @"请求失败";
                    if ([responseObject valueForKey:@"msg"] && ![[responseObject valueForKey:@"msg"] isStringContainEnglish]) {
                        resMsg = [responseObject valueForKey:@"msg"];
                    }
                    [self->_delegate getError:[NSError errorWithDomain:resMsg code:[[responseObject valueForKey:@"code"] integerValue] userInfo:nil] tag:tag];
                }
            }
        }else {
            //请求失败
            [self HideLoading];
            NSLog(@"\r\n----------------服务器错误开始----------------\r\n%@\r\n----------------服务器错误结束----------------", error);
            NSLog(@"Error: %@, %@, %@", error, response, responseObject);
            if(self->_delegate && [self->_delegate respondsToSelector:@selector(getError:tag:)]){
                if ([error.domain isStringContainEnglish]) {
                    [self->_delegate getError:[NSError errorWithDomain:@"请求失败" code:-1 userInfo:nil] tag:tag];
                }else {
                    [self->_delegate getError:[NSError errorWithDomain:error.domain code:-1 userInfo:nil] tag:tag];
                }
            }
        }
    }] resume];
    
}


#pragma mark ----- 加载动画
-(BOOL)isLoadingNow{
    
    return is_loading;
}

//加载动画
-(void)ShowLoading{
    
    is_loading = YES;
    
    self.HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    self.HUD.cornerRadius = 15;
    self.HUD.opacity = .7;
    //    self.HUD.labelText = @"正在加载...";
}

-(void)HideLoading{
    is_loading = NO;
    if (self.HUD!=nil) {
        self.HUD.delegate = nil;
        [self.HUD removeFromSuperview];
        self.HUD = nil;
    }
}

-(void)ShowNewMsg:(NSString*)str
{
    cnhbMsgAlert *alert = [[cnhbMsgAlert alloc] init];
    [alert setTextColor:[UIColor whiteColor]];
    [alert showMessage:str];
}

#pragma mark ---登录过期处理
- (void)ShowLoginOutDate:(int)loginBackType{
    
    if ([[[DataService sharedService] currentViewController] isKindOfClass:[UIViewController class]] || [[[DataService sharedService] currentViewController] isKindOfClass:[UIAlertView class]]) {
        //如果当前展示的已经是登录页面或者已经弹出警告框时 不再弹出token失效的提示框
        return;
    }
    AppDelegate *appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
    appDelegate.login_backtype = loginBackType;
    [appDelegate showloginalertview:[[DataService sharedService] currentViewController]];
}

#pragma mark - 本地证书相关
-(void)checkTs:(NSString *)timeSecStr{//更新本地服务器时间
    
    if(![timeSecStr isEqualToString:@""]){
        NSUDSetValueWithKey(timeSecStr, @"app_time");
        NSLog(@"Time Upate:%@",NSUDGetValueWithKey(@"app_time"));
    }
}


@end
